package com.ysxsoft.wdg.adapter.my;


import android.view.View;
import android.widget.ImageView;
import android.widget.TextView;

import com.bumptech.glide.Glide;
import com.chad.library.adapter.base.BaseQuickAdapter;
import com.chad.library.adapter.base.BaseViewHolder;
import com.ysxsoft.wdg.R;
import com.ysxsoft.wdg.bean.response.CollectStoreResponse;

public class CollectShopAdapter extends BaseQuickAdapter<CollectStoreResponse.DataBean,BaseViewHolder> {
    private OnDeleteClickLister mDeleteClickListener;

    public CollectShopAdapter(int layoutResId) {
        super(layoutResId);
    }

    public void clear(){
        getData().clear();
        notifyDataSetChanged();
    }


    @Override
    protected void convert(BaseViewHolder helper, CollectStoreResponse.DataBean item) {
        int position = helper.getLayoutPosition();

        helper.setText(R.id.tv_name,item.getName());
        helper.setText(R.id.tv_price,mContext.getString(R.string.price_rmb,item.getPrice()));
        helper.setText(R.id.tv_distance,item.getDistance()+"km");
        helper.setText(R.id.tv_fen,"评分"+item.getGrade());
        helper.setText(R.id.tv_sold,"已售"+item.getSold());
        Glide.with(mContext).load(item.getPic()).into((ImageView) helper.getView(R.id.iv_pic));

        TextView tv_delete = helper.getView(R.id.tv_delete);
        tv_delete.setTag(position);
        if (!tv_delete.hasOnClickListeners()) {
            tv_delete.setOnClickListener(new View.OnClickListener() {
                @Override
                public void onClick(View v) {
                    if (mDeleteClickListener != null) {
                        mDeleteClickListener.onDeleteClick(v, (Integer) v.getTag());
                    }
                }
            });
        }
    }



    public void setOnDeleteClickListener(OnDeleteClickLister listener) {
        this.mDeleteClickListener = listener;
    }

    public interface OnDeleteClickLister {
        void onDeleteClick(View view, int position);
    }
}
